/*
 * JavaScript
 */
	//	dist and co2 calculation
var Orig=new Array();
var Dest=new Array();
var nm=0;
var tc=0;
function DoCalc(form) {
from_airport=form.from.options[form.from.selectedIndex].value;
dest_airport=form.to.options[form.to.selectedIndex].value;

if (from_airport=="" || dest_airport=="") {
alert("Please select Origin and Destination City.");
//alert not working in s40 to check with forum
}
else {
Orig=from_airport.split("/");
Dest=dest_airport.split("/");
d=Math.acos(Math.sin(Orig[2])
*Math.sin(Dest[2])
+Math.cos(Orig[2])
*Math.cos(Dest[2])
*Math.cos(Orig[4]-Dest[4]));
nm=Math.round(3437.747*d);
if (Math.sin(Dest[4]-Orig[4]) < 0) {
tc=Math.acos((Math.sin(Dest[2])
-Math.sin(Orig[2])*Math.cos(d))
/(Math.sin(d)*Math.cos(Orig[2])));
} 
else { 
tc=2*Math.PI
-Math.acos((Math.sin(Dest[2])
-Math.sin(Orig[2])
*Math.cos(d))/(Math.sin(d)
*Math.cos(Orig[2])));
}
tc=Math.round(tc*(180/Math.PI));

var aircarbon = Math.round((nm*1.13636)*0.45);	
			aircarbon + 'lbs\n'
var carcarbon = Math.round(((nm*1.13636)/23.5)*19.42);	
if (aircarbon<=carcarbon){
reccom = "TRAVEL BY AIR";
}
else {
reccom = "TRAVEL BY CAR";
}

	form.textarea.value ='BY AIR - '+aircarbon +' lbs' + '\nBY CAR - ' + carcarbon +' lbs [23 miles/gallon]\n'+reccom+'\n';
			
   }
}
// End -->


